package com.ruoyi.web.controller.devicedata;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.pojo.request.devicedata.DevicePhotoRequest;
import com.ruoyi.web.pojo.vo.devicedata.DevicePhotoVO;
import com.ruoyi.web.service.devicedata.DevicePhotoService;
import com.ruoyi.web.utils.wuqing.WQRremoteCall;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(value = "虫情图片",tags = "虫情图片")
@RestController
@RequestMapping("/device-photo")
public class DevicePhotoController extends BaseController {

    @Autowired
    private DevicePhotoService devicePhotoService;

    @ApiOperation("虫情数据页-查询某一类虫的图片")
    @ApiImplicitParams({  @ApiImplicitParam(name = "deviceId",value = "设备编号", required = true) ,
            @ApiImplicitParam(name = "time",value = "日期 格式 yyyy-MM-dd", required = true) ,
            @ApiImplicitParam(name = "insectName",value = "昆虫名字")})
    @GetMapping("/getByInsectName")
    public R<List<DevicePhotoVO>> getByInsectName(@RequestParam String deviceId,@RequestParam String time,@RequestParam String insectName)
    {
        List<DevicePhotoVO> vos = devicePhotoService.getByInsectName(deviceId, time, insectName);
        return R.ok(vos);
    }

    @ApiOperation("分页查询虫情图片")
    @GetMapping("/getPhotosPage")
    public TableDataInfo<DevicePhotoVO> queryPhotoPage(DevicePhotoRequest request)
    {
        TableDataInfo<DevicePhotoVO> result = devicePhotoService.queryPhotoPage(request);
        return result;
    }

    @ApiOperation("导出图片Excel的地址")
    @GetMapping("/exportDevicePhoto")
    public AjaxResult exportDevicePhoto(DevicePhotoRequest request)
    {
        TableDataInfo<DevicePhotoVO> vos = WQRremoteCall.queryPhotoPage(request);
        List<DevicePhotoVO> rows = vos.getRows();
        ExcelUtil<DevicePhotoVO> util = new ExcelUtil<>(DevicePhotoVO.class);
        return util.exportExcel(rows, "虫情统计数据");
    }

}
